package com.ruoyi.system.aspect;


import com.ruoyi.system.utils.SnowflakeIdProcessor;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class SnowflakeIdAspect {


    /**
     * 拦截所有Mapper的insert方法，自动处理@SnowflakeId注解
     */

    @Before("execution(* com..mapper.*.insert*(..)) || execution(* com..mapper.*.save*(..))")
    public void beforeInsert(JoinPoint joinPoint) {
        Object[] args = joinPoint.getArgs();
        for (Object arg : args) {
            if (arg != null) {
                SnowflakeIdProcessor.process(arg); // 自动处理注解
            }
        }
    }
}

